home *** CD-ROM | disk | FTP | other *** search
- program DemoCl2;
-
- Uses Windows, SysUtils, Classes;
-
- const
- BuffSize = 32768;
-
- var
- Machine: ShortString;
- Option: ShortString;
- MachineBuffer: array[0..255] of char;
- CommandBuffer: array[0..255] of char;
- DataBuffer: array[0..BuffSize-1] of char;
- DataBytes: DWord;
-
- procedure ShowSyntaxOptions;
- begin
- WriteLn('DESCRIPTION');
- WriteLn(' DemoCl2 is a simple client application to communicate with the DemoSv2 Service DemoService2b using pipes.');
- WriteLn(' Supplied as part of the demonstration programs to accompany the NT services article in the Delphi Magazine.');
- WriteLn('USAGE');
- WriteLn(' DEMOCL2 MACHINE_NAME <Option>');
- WriteLn('');
- WriteLn(' MACHINE_NAME is the name of the machine (use . for the local machine)');
- WriteLn(' Options can be one of:-');
- WriteLn(' Query - do display a list of files backed up from the monitored direcotry');
- WriteLn(' Reset - to reset the list of files.');
- end;
-
- procedure ShowReturnedData;
- var
- Strings: TStrings;
- MemStream: TStream;
- I: Integer;
-
- begin
- Strings := TStringList.Create;
- try
- MemStream := TMemoryStream.Create;
- try
- MemStream.Write(DataBuffer,DataBytes);
- MemStream.Position := 0;
- Strings.LoadFromStream(MemStream);
- for I := 0 to Strings.Count - 1 do
- WriteLn(Strings[I]);
- finally
- MemStream.Free;
- end;
- finally
- Strings.Free;
- end;
- end;
-
- begin
- if (ParamCount = 0) or (ParamCount > 2) then
- ShowSyntaxOptions
- else
- begin
- Machine := UpperCase(ParamStr(1));
- if ParamCount = 1 then
- Option := 'QUERY'
- else
- Option := UpperCase(ParamStr(2));
- StrPCopy(MachineBuffer,'\\'+Machine+'\Pipe\Service2b');
- StrPCopy(CommandBuffer,Option);
- FillChar(DataBuffer,Sizeof(DataBuffer),0);
- if CallNamedPipe(@MachineBuffer,@CommandBuffer,StrLen(CommandBuffer) + 1,
- @DataBuffer,BuffSize,DataBytes,NMPWAIT_WAIT_FOREVER) then
- ShowReturnedData
- else
- begin
- WriteLn('Call to DemoService2b failed:-');
- WriteLn(Format(' ''%s''',[SysErrorMessage(GetLastError)]));
- end;
- end;
- end.
-
-